<?php
/**
 * Created by b17
 * 2/17/12 7:23 PM
 */

namespace Managers\Images;

class Cutter
{
    protected $width = null;
    protected $height;
    /**
     * @var \Managers\Naming\Policy
     */
    protected $namePolicy;

    public function __construct(\Managers\Naming\Policy $namePolicy, $width, $height = null)
    {
        $this->setNamePolicy($namePolicy);
        $this->setWidth($width);
        $this->setHeight($height);
    }

    public function setHeight($height = null)
    {
        $this->height = $height;
    }

    public function setNamePolicy(\Managers\Naming\Policy $namePolicy)
    {
        $this->namePolicy = $namePolicy;
    }

    public function setWidth($width)
    {
        $this->width = $width;
    }

    public function transform($file)
    {
        $newName = $this->namePolicy->rename($file);
        copy($file, $newName);
        \Managers\Utils::resizeImage($newName, $this->width, $this->height);
        return $newName;
    }


}
